package android.db.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.db.AbsDAO;
import android.db.Persistence;

public abstract class SQLiteDatabaseDAO<T extends Persistence> extends AbsDAO<T> {
	
	private SQLiteDatabase db;

	public SQLiteDatabaseDAO(Context context, SQLiteDatabase db) {
		super(context);
		this.db = db;
		db.execSQL(createTableCommand());
	}
	
	@Override
	protected Cursor query(String[] columns, String selection,
			String[] selectionArgs, String groupBy, String having,
			String orderBy) {
		return db.query(getTableName(), columns, selection, selectionArgs, groupBy, having, orderBy);
	}
	
	@Override
	protected  long insert(String nullColumnHack, ContentValues values) {
		return db.insert(getTableName(), nullColumnHack, values);
	}
	
	@Override
	protected int update(ContentValues values, String whereClause,
			String[] whereArgs) {
		return db.update(getTableName(), values, whereClause, whereArgs);
	}
	
	@Override
	protected int delete(String whereClause, String[] whereArgs) {
		return db.delete(getTableName(), whereClause, whereArgs);
	}
	
	@Override
	protected void execSQL(String sql) {
		db.execSQL(sql);
	}
	
	protected SQLiteDatabase getSQLiteDatabase(){
		return db;
	}
}
